﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Form.cshtml";

    //收据报表链接
    //var reportUrl = SysConfigReader.OrgReportLink();
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
    var curOpr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
}
<form>
        <div class="panel panel-default">
            <div class="panel-heading navb-bg">
                筛选条件
            </div>
            <table class="form">
                <tr>
                    <th class="formTitle">查询日期：</th>
                    <td class="formValue" colspan="2">
                        <input id="kssj" type="text" class="form-control input-wdatepicker" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        <span style="margin-left:1%;float:left">—</span>
                        <input id="jssj" type="text" class="form-control input-wdatepicker" style="width:43%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    </td>
                    <td class="formValue">
                        <input type="button" id="btn_search" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" />
                    </td>
                    <th class="formTitle"></th>
                    <td class="formValue"></td>
                </tr>
            </table>
        </div>
            <div class="dv-right gridPanel">
                <table id="gridList"></table>
                <div id="gridPager"></div>
            </div>
            <div style="background-color: #fff; margin-top:5px;">
                <table id="gridJSMXList"></table>
                <div id="gridPatPager"></div>
            </div>
        <input type="button" id="HZQD" class="btn btn-primary" style="width:60px;float:right;" value="打印" />

</form>

<script>
    var bysj = "";
    var last = "";//上一个组号

    $(function () {
        gridList();
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/NurseManage/WardMaintenance/GetDispensingItems",
            height: 180,
            postData: getpostData(),
            colModel: [
                { label: '摆药时间', name: 'bysj', width: 150, align: 'left' },
                { label: '护理单元', name: 'hldy', width: 100, align: 'left' },
                { label: '调剂者', name: 'tjz', width: 80, align: 'left' },
                { label: '医嘱数目', name: 'yzsm', width: 60, align: 'left' },
            ],
            pager: "#gridPager",
            sortname: 'bysj desc',
            viewrecords: true,
            onSelectRow_page: function (rowid) {
                btn_selectrow();
            },
            gridComplete: function (gridJszbList) {
                jszbList = null;
                if (gridJszbList && gridJszbList.rows) {
                    jszbList = gridJszbList.rows;
                }
            }
        });

        $("#btn_search").click(function () {
            $('#gridJSMXList').jqGrid("clearGridData");//先清空明细
            $gridList.jqGrid('setGridParam', {
                postData: getpostData(),
                url: "/NurseManage/WardMaintenance/GetDispensingItems",
            }).trigger('reloadGrid');
        });
    }

    var jszbList = null;

    function getpostData() {
        return {
            kssj: $("#kssj").val() + " 00:00:00", jssj: $("#jssj").val() + " 23:59:59"
        };
    }
    var lastxm = null;
    //单击事件
    function btn_selectrow() {

        var bysj = $("#gridList").jqGridRowValue().bysj;
        gridListMX(bysj);
    }
    function gridListMX(bysj) {
        var $gridList = $("#gridJSMXList");
        $gridList.jqGrid('setGridParam', {
            postData: { bysj: bysj },
            url: "/NurseManage/WardMaintenance/GetDispensingItemsMX",
        }).trigger('reloadGrid');
        $gridList.dataGrid({
            url: "/NurseManage/WardMaintenance/GetDispensingItemsMX",
            postData: { bysj: bysj },
            height: $(window).height() - 370,
            colModel: [
                {
                    label: '姓名', name: 'xm', width: 60,  align: 'center',
                    cellattr: function (rowId, tv, rawObject, cm, rdata) {
                        return 'id=\'xm' + rowId + "\'";
                    }
                },
                { label: '床标号', name: 'cw', width: 50, align: 'left' },
                { label: '病人ID', name: 'zyh', width: 50, align: 'left' },
                { label: '同组', name: 'zh', align: 'center', width: 30 },
                { label: '医嘱', name: 'yznr', width: 160, align: 'left' },
                { label: '剂量', name: 'jl', width: 50, align: 'left' },
                { label: '频次', name: 'pc', width: 50, align: 'left' },
                { label: '数量', name: 'sl', width: 40, align: 'left' },
                { label: '单位', name: 'dw', width: 40, align: 'left' },
                { label: '执行时间', name: 'zxsj', width: 140, align: 'left' },
                { label: '药品名称', name: 'ypmc', width: 160, align: 'left' },
                { label: '规格', name: 'ypgg', width: 80, align: 'left' },
                { label: '厂家', name: 'ycmc', width: 120, align: 'left' },
                { label: '应收(元)', name: 'ys', width: 50, align: 'left' },
                { label: '实收(元)', name: 'ss', width: 50, align: 'left' },
                { label: '开始时间', name: 'kssj', width: 140, align: 'left' },
                { label: '停止时间', name: 'tzsj', width: 140, align: 'left' },
                { label: '给药途径', name: 'jytj', width: 50, align: 'left' },
                { label: '费别', name: 'fb', width: 50, align: 'left' },
            ],
            pager: "#gridPatPager",
            sortname: 'xm,zh desc',
            viewrecords: true,
            gridComplete: function () {
                MergerStatistics("gridJSMXList", 'xm');
                var returnval = "";
                var ids = $("#gridJSMXList").jqGrid('getDataIDs');
                for (i = 0; i < ids.length; i++) {


                    var rowData = $("#gridJSMXList").jqGrid('getRowData', ids[i]);
                    //组号生成特殊符号
                    if (rowData.zh == "") {
                        continue;
                    }
                    if (rowData.zh != typeof (undefined) && rowData.zh !== "" && rowData.zh !== null) {
                        if (last == rowData.zh) {
                            returnval = "中间";
                            if (i == (ids.length - 1)) {//最后一个
                                returnval = "结束";
                                last = "";
                            }
                            var rowDatas = $("#gridJSMXList").jqGrid('getRowData', ids[i + 1]);
                            if (rowData.zh != rowDatas.zh || rowDatas.zh == "") {
                                returnval = "结束";
                                last = "";
                            }
                        }
                        else if (last !== rowData.zh) {
                            //if (last !== "") {
                            //	setlastrowzuhao(ids[i]);
                            //}
                            returnval = "开始";
                            var rowDatasfrist = $("#gridJSMXList").jqGrid('getRowData', ids[i + 1]);
                            if (rowData.xm != lastxm && rowData.zh != rowDatasfrist.zh) {
                                continue;
                            }
                            //else {
                            //    returnval = "结束";
                            //}
                        }
                        $("#gridJSMXList").setCell(ids[i], "zh", '<img src="../../../../Content/img/' + returnval + '.png" />');//setCell 设置单元格样式 值 或属性

                    }
                    last = rowData.zh;
                    lastxm = rowData.xm;
                }
            },
        });
    }
    function setlastrowzuhaoid(rowid,last) {
        var lastrow = parseInt(rowid);
        $("#gridJSMXList").setCell(lastrow, "zh", last);//setCell 设置单元格样式 值 或属性
    }
    function MergerStatistics(gridName, CellName) {
        //得到显示到界面的id集合
        var mya = $("#" + gridName + "").getDataIDs();
        //当前显示多少条
        var length = mya.length;
        for (var i = 0; i < length; i++) {
            //从上到下获取一条信息
            var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
            //定义合并行数
            var rowSpanTaxCount = 1;
            for (j = i + 1; j <= length; j++) {
                //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
                var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
                var cellNames = CellName.split(",");
                for (var n = 0; n < cellNames.length; n++) {
                    if (before[cellNames[0]] == end[cellNames[0]]) {
                        rowSpanTaxCount++;
                        $("#" + gridName + "").setCell(mya[j], cellNames[0], '', { display: 'none' });
                    } else {
                        rowSpanTaxCount = 1;
                        break;
                    }
                    $("#" + cellNames[0] + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);//最后合并需要合并的行与合并的行数
                    $("#" + cellNames[0] + "" + mya[i] + "").attr("position", "relative");
                    $("#" + cellNames[0] + "" + mya[i] + "").attr("top", "50%");
                    $("#" + cellNames[0] + "" + mya[i] + "").attr("transform", "translateY(-50%)");

                }

            }

        }

    }
    //结算明细 jGrid声明
    //$('#gridJSMXList').newtouchLocalDataGrid({
    //    height: $(window).height() - 370,
    //    caption: "药品医嘱信息",
    //    pager: "#gridPatPager",
    //    sortname: 'zh',
    //    viewrecords: true,
    //    colModel: [

    //        { label: '姓名', name: 'xm', width: 60, align: 'left' },
    //        { label: '床标号', name: 'cw', width: 50, align: 'left' },
    //        { label: '病人ID', name: 'zyh', width: 50, align: 'left' },
    //        { label: '同组', name: 'zh', align: 'center', width: 30 },
    //        { label: '医嘱', name: 'yznr', width: 160, align: 'left' },
    //        { label: '剂量', name: 'jl', width: 50, align: 'left' },
    //        { label: '频次', name: 'pc', width: 50, align: 'left' },
    //        { label: '数量', name: 'sl', width: 40, align: 'left' },
    //        { label: '单位', name: 'dw', width: 40, align: 'left' },
    //        { label: '执行时间', name: 'zxsj', width: 140, align: 'left' },
    //        { label: '药品名称', name: 'ypmc', width: 160, align: 'left' },
    //        { label: '规格', name: 'ypgg', width: 80, align: 'left' },
    //        { label: '厂家', name: 'ycmc', width: 120, align: 'left' },
    //        { label: '应收(元)', name: 'ys', width: 50, align: 'left' },
    //        { label: '实收(元)', name: 'ss', width: 50, align: 'left' },
    //        { label: '开始时间', name: 'kssj', width: 140, align: 'left' },
    //        { label: '停止时间', name: 'tzsj', width: 140, align: 'left' },
    //        { label: '给药途径', name: 'jytj', width: 50, align: 'left' },
    //        { label: '费别', name: 'fb', width: 50, align: 'left' },
    //    ],
    //    gridComplete: function () {
    //        var returnval = "";
    //        var ids = $("#gridJSMXList").jqGrid('getDataIDs');
    //        for (i = 0; i < ids.length; i++) {
    //
    //            var rowData = $("#gridJSMXList").jqGrid('getRowData', ids[i]);
    //            //组号生成特殊符号
    //            if (rowData.zh == "") {
    //                continue;
    //            }
    //            if (rowData.zh != typeof (undefined) && rowData.zh !== "" && rowData.zh !== null) {
    //                if (last == rowData.zh) {
    //                    returnval = "中间";
    //                    if (i == (ids.length - 1)) {//最后一个
    //                        returnval = "结束";
    //                        last = "";
    //                    }
    //                    var rowDatas = $("#gridJSMXList").jqGrid('getRowData', ids[i + 1]);
    //                    if (rowData.zh != rowDatas.zh || rowDatas.zh == "") {
    //                        returnval = "结束";
    //                        last = "";
    //                    }
    //                }
    //                else if (last !== rowData.zh) {
    //                    returnval = "开始";
    //                }
    //                $("#gridJSMXList").setCell(ids[i], "zh", '<img src="../../../../Content/img/' + returnval + '.png" />');//setCell 设置单元格样式 值 或属性

    //            }
    //            last = rowData.zh;
    //        }
    //    },
    //});

    function setlastrowzuhao(rowid) {
        var lastrow = parseInt(rowid) - 1;
        $("#gridJSMXList").setCell(lastrow, "zh", '<img src="../../../../Content/img/结束.png" />');//setCell 设置单元格样式 值 或属性
    }
    //打印汇总清单

    var curUserCode = '@(ViewBag.CurUserCode)';
    //打印明细
    var srcUrl = "";
    $("#HZQD").click(function () {
        var reportServerHOST = '@ViewBag.ReportServerHOST';

        var orgId = '@(ViewBag.OrgId)';

        var uri = '@reportUrl' + "?tempCode=45" + "&systemCode=" + '@reportSystemCode' + "&orgId=" + '@curOpr.OrganizeId' + "&bysj=" + $("#gridList").jqGridRowValue().bysj;
        window.open(uri);

        //var urldy = "/ReportServer/Pages/ReportViewer.aspx?%2fNewtouch.Report.1%2f药品医嘱信息打印&rs:Command=Render&rc:Stylesheet=MyStyleSheet&orgId=" + orgId + "&bysj=" + $("#gridList").jqGridRowValue().bysj;
        //if (urldy.StartWith('/')) {
        //    urldy = urldy.substr(1);
        //}
        //srcUrl= urldy;
        //srcUrl = reportServerHOST + srcUrl;

        //window.open(srcUrl);


    })

</script>
<script type="text/javascript">
    function printFp(jsnm) {
        var uri = '@Html.Raw(reportUrl)' + "&jsnm=" + jsnm + "&systemCode=" + '@reportSystemCode';
        window.open(uri, "_blank", "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
    }

    //发票补打
    function supplementprintFp(jsnm) {
        tempJSNM = jsnm;
        $.modalOpen({
            id: "InvoiceNoPanel",
            title: "选发票号",
            url: "/OutpatientManage/OutpatientReg/ChooseInvoice",
            width: "300px",
            height: "200px",
            callBack: function (iframeId) {
                top.frames[iframeId].checkFPH();//窗口点确定的回调函数
            }
        });

    }

    var tempJSNM;
    //补打，选择了新的发票号
    function chooseFPHSuccessCallback(fph) {
        //更新结算记录的发票号为新发票号
        $.najax({
            type: "POST",
            url: "/HospitalizationManage/Settlement/UpdateSettInvoiceNo",
            data: { jsnm: tempJSNM, fph: fph },
            dataType: "json",
            success: function (data) {
                //打印
                printFp(tempJSNM);
            }
        });
    }

    


</script>
